$(function () {

    init();
})

function init() {
    FastClick.attach(document.body);
    var flowCode = getQueryString("flowCode");
    equipmemtService.queryPersonInformation({}, function (data) {
        if (data.success) {
            userId = data.data[0].staffId;
            userName = data.data[0].name;
            userRole = data.data[0].cRoleName;
            userRoleId = data.data[0].cRoleId;
            bindMenu(userRoleId);
            organizationName = data.data[0].organizationName + data.data[0].organizationNameSon
            $("#userName").html(userRole + ":" + userName);
            // $("#userOrgName").html(organizationName);
            equipmemtService.queryEquipmentDetail({QRcode: QRcode, flowCode: flowCode}, function (data) {
                if (data.success) {
                    serverData = data.data;
                    if (data.errorMsg == "notActive") {
                        $.alert("未激活的二维码，请录入固定资产信息即可绑定此二维码", function () {
                            $(".weui-mask").remove();
                            $("body").append('<div class="weui-mask weui-mask--visible"></div>');
                            form = $("<div class='form TA'></div>");
                            form.append("<div class='flex'><div class='label'>固定资产类型和品牌</div><div class='value'><input id='etype' placeholder='请选择' readonly='readonly' /></div></div>");
                            form.append("<div class='flex'><div class='label'>固定资产型号</div><div class='value'><input id='emodel' placeholder='请选择'readonly='readonly' /></div></div>");
                            form.append("<div class='flex' style='display:none;' id='newModel'><div class='label'>其他型号</div><div class='value'><input id='emodelNew' placeholder='请输入' /></div></div>");
                            form.append("<div class='flex'><div class='label'>领用日期</div><div class='value'><input id='buyTime' placeholder='请选择'readonly='readonly' /></div></div>");
                            form.append("<div class='flex'><div class='label'>使用方式</div><div class='value'><input id='useType' placeholder='请选择'readonly='readonly' /></div></div>");
                            form.append("<div class='flex'><div class='label'>配置描述</div></div><div class='flex'><div class='value'><textarea id='einfo' placeholder='请输入固定资产的详细配置内容（500字以内）'></textarea></div></div>");
                            form.append("<div class='flex'><div class='label'>使用位置</div><div class='value'><input id='eposition' placeholder='请输入使用位置（100字以内）' /></div></div>");
                            form.append("<div class='flex'><div class='label'>固定资产编号</div><div class='value'><input id='ebarcode' placeholder='请输入固定资产条码（出厂唯一标识）'/></div></div>");
                            form.find("#etype").picker({
                                title: "固定资产类型和品牌",
                                cols: [
                                    {
                                        textAlign: 'center',
                                        values: baseService.getServerConstNames("type")
                                    },
                                    {
                                        textAlign: 'center',
                                        values: baseService.getServerConstNames("brand")
                                    }
                                ],
                                onClose: loademodel
                            });
                            form.find("#useType").picker({
                                title: "使用方式",
                                cols: [
                                    {
                                        textAlign: 'center',
                                        values: baseService.getServerConstNames("useType")
                                    }
                                ]
                            });
                            form.find("#buyTime").calendar({
                                dateFormat: 'yyyy-mm-dd'
                            });
                            var imgUpload = $("<div class='flex'><div class='label'>上传图片（请上传固定资产相关照片）</div></div><div class='flex'><div class='value'>" +
                                "<div class='imgUpBox'  id='imgButton1' style='background-image:url(/assets/user/images/p1.png) '><img  id=\"eImg\"  src=''/><div class='imgButton'>上传外观</div></div>" +
                                "<div class='imgUpBox'  id='imgButton2' style='background-image:url(/assets/user/images/p2.png) '><img  id=\"eImg2\" src=''/><div class='imgButton'>上传铭牌</div></div>" +
                                "<div  style='display: none'><input type='file' id='newImg' accept='image/*'/></div>" +
                                "<div  style='display: none'><input type='file' id='newImg2' accept='image/*'/></div>" +
                                "</div></div>");
                            form.append(imgUpload);
                            imgUpload.find("#imgButton1").on("click", function () {
                                imgUpload.find("#newImg").trigger("click");
                            });
                            imgUpload.find("#imgButton2").on("click", function () {
                                imgUpload.find("#newImg2").trigger("click");
                            });
                            imgUpload.find("#newImg").on("change", function () {
                                var file = imgUpload.find("#newImg")[0].files;
                                imgZip(file, imgUpload.find("#eImg"), 800, 800);
                            });
                            imgUpload.find("#newImg2").on("change", function () {
                                var file = imgUpload.find("#newImg2")[0].files;
                                imgZip(file, imgUpload.find("#eImg2"), 800, 800);
                            });
                            close = $("<span class='close fa fa-home'> </span>");
                            close.on("click", function () {
                                window.location.href = "/userMain";
                            }).css("left", "20px");
                            submit = $("<span class='submit fa fa-check'> 确认</span>");
                            submit.on("click", function () {
                                $.confirm("是否确认保存固定资产信息？", '确认', function () {

                                    var param = {};
                                    var etype = form.find("#etype").val().split(" ");
                                    param.id = "";
                                    param.QRCode = serverData.QRCode;
                                    param.organizationId = serverData.organizationId;
                                    param.oneCode = baseService.getServerConstCodeByName("type", etype[0]);
                                    param.brandCode = baseService.getServerConstCodeByName("brand", etype[1]);
                                    param.model = form.find("#emodel").val();
                                    param.buyTime = form.find("#buyTime").val();
                                    param.usePosition = form.find("#eposition").val();
                                    param.configurationDescription = form.find("#einfo").val();
                                    param.barCode = form.find("#ebarcode").val();
                                    param.useType = baseService.getServerConstCodeByName("useType", form.find("#useType").val());
                                    param.newModel = form.find("#emodelNew").val();
                                    param.useStaffId = userId;
                                    param.modelId = baseService.getServerConstCodeByName("model", form.find("#emodel").val());
                                    param.warehouseId = "-1";
                                    if (param.model == "其他") {
                                        if (param.newModel.trim() == "") {
                                            $.alert("请输入其他型号的具体描述", "提醒", function () {
                                                form.find("#newModel").focus()
                                            });
                                            return;
                                        } else {
                                            param.model = param.newModel;
                                        }
                                    }
                                    var scoreImg = imgUpload.find("#eImg").attr("src");
                                    if (scoreImg.startsWith("data:image")) {
                                        param.externalPhotos = scoreImg;
                                    } else {
                                        param.externalPhotos = "";
                                    }
                                    var scoreImg2 = imgUpload.find("#eImg2").attr("src");
                                    if (scoreImg2.startsWith("data:image")) {
                                        param.nameplatePhoto = scoreImg2;
                                    } else {
                                        param.nameplatePhoto = "";
                                    }
                                    param.source = "124001";
                                    equipmemtService.editEquipment(param, function (data) {
                                        if (data.success) {
                                            formHide();
                                            location.reload();
                                        } else {
                                            $.alert(data.errorMsg);
                                        }
                                    });

                                })

                            }).css("left", "130px").css("right", "20px");
                            $("body").append(form);
                            $("body").append(close);
                            $("body").append(submit);
                            // form.on("click", function (e) {
                            //     var top = $(e.target).offset().top;
                            //     form.scrollTop(top);
                            //     $(e.target).focus();
                            // })
                        })
                        $("#menus").html("");
                        return;
                    }
                    if (serverData.product&&(serverData.product.length > 0)) {
                        $("#product").show();
                        $("#product").on("click", function () {
                            window.location.href = "/pdetail/" + serverData.product[0].code;
                        })
                    }
                    if (serverData.Equipment.externalPhotos != null && serverData.Equipment.externalPhotos != "") {
                        $(".pic").css("background-image", "url(" + serverData.Equipment.externalPhotos + ")");
                        $("#pic").css("background-image", "url(" + serverData.Equipment.externalPhotos + ")");
                    } else {
                        $(".pic").css("background-image", "url(" + serverData.Equipment.modelImage + ")");
                        $("#pic").css("background-image", "url(" + serverData.Equipment.modelImage + ")");
                    }

                    if (serverData.Equipment.state != "203003") $("#edit").hide();

                    $("#secret").html(" " + baseService.getServerConstNameByCode("secrecy", serverData.Equipment.secrecy));
                    if(serverData.Equipment.secrecy>"116001"){
                        $("#edit").hide();
                    }
                    $("#name").html(serverData.Equipment.name + "<span class=\"fa fa-cog TA s1\"> " + equipmemtService.getStateText(serverData.Equipment.state) + "</span>");
                    var span = $("#name span");
                    if(serverData.Equipment.state=="203001"){
                        setInterval(function () {
                            if (span.hasClass("s1"))
                                span.removeClass("s1").addClass("s2")
                            else span.removeClass("s2").addClass("s1")
                        }, 800);
                    }else{
                        setInterval(function () {
                            if (span.hasClass("s1"))
                                span.removeClass("s1").addClass("s3")
                            else span.removeClass("s3").addClass("s1")
                        }, 800);
                    }

                    if(serverData.Equipment.name!=null && (serverData.Equipment.name.split("-").length==3)){
                        $("#eType").html(serverData.Equipment.name.split("-")[0]);
                        $("#eBrand").html(serverData.Equipment.name.split("-")[1]);
                    }else{
                        $("#eType").parent().hide();
                        $("#eBrand").parent().hide();
                    }
                    if (serverData.Equipment.model == null)
                        $("#eModel").parent().hide();
                    else
                        $("#eModel").html(serverData.Equipment.model);
                    if (serverData.Equipment.barCode == null)
                        $("#eBarCode").parent().hide();
                    else
                        $("#eBarCode").html(serverData.Equipment.barCode);
                    if (serverData.Equipment.organizationName == null)
                        $("#eOrgName").parent().hide();
                    else
                        $("#eOrgName").html(serverData.Equipment.organizationName);
                    if (serverData.Equipment.useStaffName == null)
                        $("#useStaffName").parent().hide();
                    else
                        $("#useStaffName").html(serverData.Equipment.useStaffName);
                    if (serverData.Equipment.changeCode == null)
                        $("#flowCode").parent().hide();
                    else
                        $("#flowCode").html(serverData.Equipment.changeCode);
                    if (serverData.Equipment.useType == null)
                        $("#useType").parent().hide();
                    else
                        $("#useType").html(baseService.getServerConstNameByCode("useType", serverData.Equipment.useType));
                    if (serverData.Equipment.usePosition == null)
                        $("#usePosition").parent().hide();
                    else
                        $("#usePosition").html(serverData.Equipment.usePosition);
                    if (serverData.Equipment.buyTime == null)
                        $("#buyTime").parent().hide();
                    else
                        $("#buyTime").html(serverData.Equipment.buyTime.substr(0, 10));
                    $("#eCertCode").html(serverData.Equipment.certCode);
                    bindShowImg();
                    if (serverData.MaintenanceApplication) {
                        $("#center").append("<div class=\"gruop\">报修信息</div> " +
                            "        <div class=\"row secret\" > " +
                            "            <div class=\"label\">报修类型</div> " +
                            "            <div class=\"value\">" + serverData.MaintenanceApplication.questionTypeName + "</div> " +
                            "        </div> " +
                            "        <div class=\"row secret\"> " +
                            "            <div class=\"value\">" + serverData.MaintenanceApplication.questionDescripe + "</div> " +
                            "        </div> " +
                            "        <div class=\"row secret\" > " +
                            "            <div class=\"label\">报修人电话</div> " +
                            "            <div class=\"value\">" + serverData.MaintenanceApplication.telephone + "</div> " +
                            "        </div> " +
                            "        <div class=\"row secret\" > " +
                            "            <div class=\"label\">报修时间</div> " +
                            "            <div class=\"value\">" + serverData.MaintenanceApplication.createTime + "</div> " +
                            "        </div> " +
                            "        <div class=\"row secret\" > " +
                            "            <div class=\"flex\"  id='img1'> " +
                            "               </div> " +
                            "        </div>");
                        var img1 = $("#center #img1");//补充说明展示
                        bindShowImg();
                    }

                    if (serverData.submitRecord) {
                        var submitRecord = $("<div class=\"gruop\">维修人信息</div> " +
                            "        <div class=\"row \" > " +
                            "            <div class=\"label\">派单时间</div> " +
                            "            <div class=\"value\">" + serverData.submitRecord.createTime + "</div> " +
                            "        </div> " +
                            "        <div class=\"row \" > " +
                            "            <div class=\"label\">维修人姓名</div> " +
                            "            <div class=\"value\">" + serverData.submitRecord.repairName + "</div> " +
                            "        </div> " +
                            "        <div class=\"row \" > " +
                            "            <div class=\"label\">维修人电话</div> " +
                            "            <div class=\"value\"><a href=\"tel:18636895231\" class='fa fa-phone' style='color: #d07007'> " + serverData.submitRecord.telephone + "</a></div> " +
                            "        </div> ");
                        $("#center").append(submitRecord);

                    }

                    if (serverData.changeInfo) {
                        $("#center").append("<div class=\"gruop\">审核信息</div> " +
                            "        <div class=\"row \" > " +
                            "            <div class=\"label\">审核时间</div> " +
                            "            <div class=\"value\">" + serverData.changeInfo.checkTime + "</div> " +
                            "        </div> " +
                            "        <div class=\"row \"> " +
                            "            <div class=\"value\">" + serverData.changeInfo.remark + "</div> " +
                            "        </div> ");
                    }
                } else if (data.errorMsg == "0-非法二维码！") {
                    $.confirm("未认证用户不允许激活二维码，是否去认证？", function () {
                        window.location.href = "/login";
                    }, function () {
                        document.addEventListener('WeixinJSBridgeReady', function () {
                            WeixinJSBridge.call('closeWindow');
                        }, false);
                        //这个可以关闭ios系统的手机
                        WeixinJSBridge.call('closeWindow');
                    });
                } else {
                    $.alert(data.errorMsg, function () {
                        history.back();
                        //这个可以关闭安卓系统的手机
                        document.addEventListener('WeixinJSBridgeReady', function () {
                            WeixinJSBridge.call('closeWindow');
                        }, false);
                        //这个可以关闭ios系统的手机
                        WeixinJSBridge.call('closeWindow');
                    });
                }
            })
        } else {
            $.alert(data.errorMsg, function () {
                window.location.href = "/logout";
            });
        }
    })


}

function bindShowImg() {
    $(".imgBox").css("height", $(".imgBox").width() + "px");
    $(".imgBox").on("click", function (e) {
        var imgBox = $(e.target);
        $(".weui-mask").remove();
        $("body").append('<div class="weui-mask weui-mask--visible"></div>');
        var imgShow = $("<div class='imgShow'></div>");
        var close = $("<span class='close fa fa-times'> </span>");
        $("body").append(imgShow);
        imgShow.css("background-image", imgBox.css("background-image"));
        close.on("click", function () {
            $(".weui-mask").remove();
            imgShow.remove();
            close.remove();
            $("body").off("touchmove");
            $("body").off("touchend");
        })
        $("body").append(imgShow);
        $("body").append(close);
        var box = imgShow[0];
        var boxGesture = setGesture(box);  //得到一个对象
        boxGesture.gesturestart = function () {  //双指开始
            // box.style.backgroundColor="yellow";
        };
        boxGesture.gesturemove = function (e) {  //双指移动
            // box.innerHTML = e.scale+"<br />"+e.rotation;
            box.style.transform = "scale(" + e.scale + ")";//改变目标元素的大小
            // box.style.transform="scale("+e.scale+") rotate("+e.rotation+"deg)";//改变目标元素的大小和角度
            // close.html( box.style.transform);
        };
        boxGesture.gestureend = function () {  //双指结束
            // box.innerHTML="";
            // box.style.cssText="background-color:red";
        };
    })
}

function bindMenu(userRoleId) {
    switch (userRoleId) {
        case "1":
            $("#menus").html('<div class="menuButton" id="main" ><span class="fa fa-home"> 个人首页</span></div> ' +
                '    <div class="menuButton" id="fix"><span class="fa fa-tools"> 我要报修</span></div> ' +
                '    <div class="menuButton" id="edit"><span class="fa fa-edit"> 修改信息</span></div> ');
            break;
        case "2":
            $("#menus").html('<div class="menuButton" id="main" ><span class="fa fa-home"> 个人首页</span></div> ' +
                '    <div class="menuButton" id="fix"><span class="fa fa-tools"> 我要报修</span></div> ' +
                '    <div class="menuButton" id="edit"><span class="fa fa-edit"> 修改信息</span></div> ');
            break;
        case "3":
            $("#menus").html('<div class="menuButton" id="main" ><span class="fa fa-home"> 个人首页</span></div> ' +
                '    <div class="menuButton" id="fix"><span class="fa fa-tools"> 我要报修</span></div> ' +
                '    <div class="menuButton" id="help"><span class="fa fa-headset"> 联系客服</span></div>');
            break;
        case "4":
            $("#menus").html('<div class="menuButton" id="main" ><span class="fa fa-home"> 个人首页</span></div> ' +
                '    <div class="menuButton" id="fix"><span class="fa fa-tools"> 我要报修</span></div> ' +
                '    <div class="menuButton" id="help"><span class="fa fa-headset"> 联系客服</span></div>');
            break;
        case "5":
            $("#menus").html('<div class="menuButton" id="main" ><span class="fa fa-home"> 个人首页</span></div> ' +
                '    <div class="menuButton" id="fix"><span class="fa fa-tools"> 我要报修</span></div> ' +
                '    <div class="menuButton" id="edit"><span class="fa fa-edit"> 修改信息</span></div> ');
            break;
        case "0":
            $("#menus").html('<div class="menuButton" id="login" ><span class="fa fa-user"> 我要认证</span></div> ' +
                '    <div class="menuButton" id="fix"><span class="fa fa-tools"> 我要报修</span></div> ' +
                '    <div class="menuButton" id="help"><span class="fa fa-headset"> 联系客服</span></div>');
            break;
        default :
            $("#menus").html('<div class="menuButton" id="login" ><span class="fa fa-user"> 我要认证</span></div> ' +
                '    <div class="menuButton" id="fix"><span class="fa fa-tools"> 我要报修</span></div> ' +
                '    <div class="menuButton" id="help"><span class="fa fa-headset"> 联系客服</span></div>');
            break;
    }
    $("#main").on("click", function () {
        window.location.href = "/userMain"
    })
    $("#login").on("click", function () {
        window.location.href = "/login"
    })
    $("#fix").on("click", function () {
        if ($("#name span").html() != " 运行中") {
            $.alert("固定资产状态非运行中，暂时无法发起维修申请！");
            return;
        }
        $(".weui-mask").remove();
        $("body").append('<div class="weui-mask weui-mask--visible"></div>');
        form = $("<div class='form TA'></div>");
        form.append("<div class='flex'><div class='label'>报修人手机</div><div class='value'><input id='telephone' placeholder='请输入您的手机号'/></div></div>");
        form.append("<div class='flex'><div class='label'>选择问题类型</div><div class='value'><input id='etype' placeholder='请选择'/></div></div>");
        form.append("<div class='flex'><div class='label'>问题描述</div></div><div class='flex'><div class='value'><textarea id='einfo' placeholder='请输入问题描述（500字以内）'></textarea></div></div>");
        var imgUpload = $("<div class='flex'><div class='label'>上传图片（请上传相关照片）</div></div><div class='flex'><div class='value'>" +
            "<div class='imgUpload weui-uploader__input-box'><input type='file' id='newImg' class='weui-uploader__input' accept='image/*'/></div>" +
            "</div></div>");
        form.append(imgUpload);
        imgUpload.find("#newImg").on("change", function () {
            var showImg = $("<img  id=\"eImg\" style=\"float:left;margin:10px;width:calc(33.3% - 20px);\" />");
            imgUpload.find("#newImg").parent().before(showImg)
            var file = imgUpload.find("#newImg")[0].files;
            imgZip(file, showImg, 800, 800);
            if (imgUpload.find("#newImg").parent().parent().children().length == 4) {
                imgUpload.find("#newImg").parent().hide();
            }
            showImg.on("click", function () {
                $.confirm("是否删除图片重新上传", "删除", function () {
                    showImg.remove();
                    imgUpload.find("#newImg").parent().show();
                })
            })
        });
        form.find("#etype").picker({
            title: "选择问题类型",
            cols: [
                {
                    textAlign: 'center',
                    values: baseService.getServerConstNames("question")
                }
            ]
        })

        close = $("<span class='close fa fa-times'> </span>");
        close.on("click", function () {
            formHide();
        }).css("left", "20px");
        submit = $("<span class='submit fa fa-check'> 确认</span>");
        submit.on("click", function () {
            $.confirm("是否确认申请维修？", '确认', function () {

                var param = {};
                var etype = form.find("#etype").val();
                param.questionTypeCode = baseService.getServerConstCodeByName("question", etype);
                param.telephone = form.find("#telephone").val();
                param.questionDescripe = form.find("#einfo").val();
                param.equipmentId = serverData.Equipment.id;
                param.code = serverData.Equipment.QRcode;
                param.eType = serverData.Equipment.oneCode;
                var repairSupplement = imgUpload.find("img");
                param.repairSupplement = [];
                for (var i = 0; i < repairSupplement.length; i++) {
                    param.repairSupplement.push(repairSupplement[i].src);
                }
                equipmemtService.applyRepair(param, function (data) {
                    if (data.success) {
                        formHide();
                        location.reload();
                    } else {
                        $.alert(data.errorMsg);
                    }
                });

            })
        }).css("left", "130px").css("right", "20px");
        $("body").append(form);
        $("body").append(close);
        $("body").append(submit);
        form.find("#telephone").focus();
    })
    $("#edit").on("click", function () {
        $(".weui-mask").remove();
        $("body").append('<div class="weui-mask weui-mask--visible"></div>');
        form = $("<div class='form TA'></div>");
        var editAble = false;
        if (serverData.Equipment.changeType == "333100") editAble = true;
        form.append("<div class='flex'><div class='label'>固定资产类型和品牌</div><div class='value'><input id='etype' placeholder='请选择' readonly='readonly' value='" + baseService.getServerConstNameByCode("type", serverData.Equipment.oneCode) + " " + serverData.Equipment.name.split("-")[1] + "'/></div></div>");
        form.append("<div class='flex'><div class='label'>固定资产型号</div><div class='value'><input id='emodel' placeholder='请选择' readonly='readonly' value='" + serverData.Equipment.model + "'/></div></div>");
        form.append("<div class='flex' style='display:none;' id='newModel'><div class='label'>其他型号</div><div class='value'><input id='emodelNew' placeholder='请输入' /></div></div>");
        form.append("<div class='flex'><div class='label'>领用日期</div><div class='value'><input id='buyTime' placeholder='请选择' readonly='readonly'  value='" + serverData.Equipment.buyTime.substring(0, 10) + "'/></div></div>");
        if (editAble) form.append("<div class='flex'><div class='label'>使用方式</div><div class='value'><input id='useType' placeholder='请选择' readonly='readonly' value='" + baseService.getServerConstNameByCode("useType", serverData.Equipment.useType) + "' /></div></div>");
        form.append("<div class='flex'><div class='label'>配置描述</div></div><div class='flex'><div class='value'><textarea id='einfo' placeholder='请输入固定资产的详细配置内容（500字以内）'>" + (serverData.Equipment.configurationDescription == "null" ? "" : serverData.Equipment.configurationDescription) + "</textarea></div></div>");
        form.append("<div class='flex'><div class='label'>使用位置</div><div class='value'><input id='eposition' placeholder='请输入使用位置（100字以内）' value='" + serverData.Equipment.usePosition + "'/></div></div>");
        form.append("<div class='flex'><div class='label'>固定资产条码</div><div class='value'><input id='ebarcode' placeholder='请输入固定资产条码（出厂唯一标识）' value='" + serverData.Equipment.barCode + "'/></div></div>");
        form.find("#etype").picker({
            title: "固定资产类型和品牌",
            cols: [
                {
                    textAlign: 'center',
                    values: baseService.getServerConstNames("type")
                },
                {
                    textAlign: 'center',
                    values: baseService.getServerConstNames("brand")
                }
            ],
            onClose: loademodel
        });
        loademodel();
        form.find("#emodel").val(serverData.Equipment.model);
        if (editAble) form.find("#useType").picker({
            title: "使用方式",
            cols: [
                {
                    textAlign: 'center',
                    values: baseService.getServerConstNames("useType")
                }
            ]
        });
        form.find("#buyTime").calendar({
            dateFormat: 'yyyy-mm-dd'
        });
        var imgUpload = $("<div class='flex'><div class='label'>上传图片（请上传固定资产相关照片）</div></div><div class='flex'><div class='value'>" +
            "<div class='imgUpBox' id='imgButton1' style='background-image:url(/assets/user/images/p1.png) '><img  id=\"eImg\"  src='" + serverData.Equipment.externalPhotos + "'/><div class='imgButton' >上传外观</div></div>" +
            "<div class='imgUpBox' id='imgButton2' style='background-image:url(/assets/user/images/p2.png) '><img  id=\"eImg2\" src='" + serverData.Equipment.nameplatePhoto + "'/><div class='imgButton' >上传铭牌</div></div>" +
            "<div  style='display: none'><input type='file' id='newImg' accept='image/*'/></div>" +
            "<div  style='display: none'><input type='file' id='newImg2' accept='image/*'/></div>" +
            "</div></div>");
        form.append(imgUpload);
        imgUpload.find("#imgButton1").on("click", function () {
            imgUpload.find("#newImg").trigger("click");
        });
        imgUpload.find("#imgButton2").on("click", function () {
            imgUpload.find("#newImg2").trigger("click");
        });
        imgUpload.find("#newImg").on("change", function () {
            var file = imgUpload.find("#newImg")[0].files;
            imgZip(file, imgUpload.find("#eImg"), 800, 800);
        });
        imgUpload.find("#newImg2").on("change", function () {
            var file = imgUpload.find("#newImg2")[0].files;
            imgZip(file, imgUpload.find("#eImg2"), 800, 800);
        });
        close = $("<span class='close fa fa-times'> </span>");
        close.on("click", function () {
            formHide();
        }).css("left", "20px");
        submit = $("<span class='submit fa fa-check'> 确认</span>");
        submit.on("click", function () {
            $.confirm("是否确认修改固定资产信息？", '确认', function () {

                var param = serverData.Equipment;
                var etype = form.find("#etype").val().split(" ");
                param.oneCode = baseService.getServerConstCodeByName("type", etype[0]);
                param.brandCode = baseService.getServerConstCodeByName("brand", etype[1]);
                param.model = form.find("#emodel").val();
                param.buyTime = form.find("#buyTime").val();
                param.usePosition = form.find("#eposition").val();
                param.configurationDescription = form.find("#einfo").val();
                param.barCode = form.find("#ebarcode").val();
                if (form.find("#useType").length > 0) param.useType = baseService.getServerConstCodeByName("useType", form.find("#useType").val());
                param.newModel = form.find("#emodelNew").val();
                param.modelId = baseService.getServerConstCodeByName("model", form.find("#emodel").val());
                if (param.model == "其他") {
                    if (param.newModel.trim() == "") {
                        $.alert("请输入其他型号的具体描述", "提醒", function () {
                            form.find("#newModel").focus()
                        });
                        return;
                    } else {
                        param.model = param.newModel;
                    }
                }

                var scoreImg = imgUpload.find("#eImg").attr("src");
                if (scoreImg.startsWith("data:image")) {
                    param.externalPhotos = scoreImg;
                } else {
                    param.externalPhotos = "";
                }
                var scoreImg2 = imgUpload.find("#eImg2").attr("src");
                if (scoreImg2.startsWith("data:image")) {
                    param.nameplatePhoto = scoreImg2;
                } else {
                    param.nameplatePhoto = "";
                }
                param.source = "124001";
                equipmemtService.editEquipment(param, function (data) {
                    if (data.success) {
                        formHide();
                        location.reload();
                    } else {
                        $.alert(data.errorMsg);
                    }
                });

            })

        }).css("left", "130px").css("right", "20px");
        $("body").append(form);
        $("body").append(close);
        $("body").append(submit);
        form.find("textarea").focus();
        form.on("click", function (e) {
            $(e.target).focus();
        })
    })
    $("#help").on("click", function () {
        $.alert(
            "<div class='tel'> <a href=\"tel:18636895231\" style='color:#676767'><span class=\"fas fa-phone-square\"> </span> 18636895231</a></div>" +
            " <div class='tel'><a href=\"tel:15035164839\" style='color:#676767'><span class=\"fas fa-phone-square\"> </span> 15035164839</a></div>", "联系客服");
    })
}

function formHide() {
    $(".weui-mask").remove();
    form.css("transform", "scale(0.1)").css("opacity", "0.1");
    setTimeout(function () {
        form.remove();
    }, 300)
    close.remove();
    submit.remove();
}

function loademodel() {
    serverConst.model = [{
        code: "-1",
        name: "其他"
    }];
    var etype = form.find("#etype").val().split(" ");
    form.find("#emodel").val("");
    equipmemtService.loadEmodel({
        oneCode: baseService.getServerConstCodeByName("type", etype[0]),
        brandCode: baseService.getServerConstCodeByName("brand", etype[1])
    }, function (data) {
        if (data.success) {
            var array = [];
            $(data.datas).each(function (index, item) {
                serverConst.model.push({
                    code: item.id,
                    image: item.image,
                    name: item.name + "-" + item.code
                });
                array.push(item.name + "-" + item.code);
            })
            array.push("其他");
            var oldEmodel = form.find("#emodel");
            oldEmodel.after("<input id='emodel' placeholder='请选择'  value='" + oldEmodel.val() + "'/>");
            oldEmodel.remove();
            var picker = form.find("#emodel").picker({
                title: "固定资产型号" + etype,
                cols: [
                    {
                        textAlign: 'center',
                        values: array
                    }
                ],
                onClose: function () {
                    if (form.find("#emodel").val() == "其他") {
                        form.find("#newModel").slideDown();
                    } else {
                        form.find("#newModel").slideUp();
                        $(".weui-mask").remove();
                        $("body").append('<div class="weui-mask weui-mask--visible"></div>');
                        var imgShow = $("<div class='imgShow'></div>");
                        var close = $("<span style='width: calc(100% - 100px);' class='submit fa fa-check'> 确认型号无误</span>");
                        $("body").append(imgShow);
                        var imageUrl = baseService.getServerConstObjByName("model", form.find("#emodel").val()).image;
                        imgShow.css("background-image", "url(" + imageUrl + ")");
                        close.on("click", function () {
                            $(".weui-mask").remove();
                            imgShow.remove();
                            close.remove();
                        })
                        $("body").append(imgShow);
                        $("body").append(close);
                    }
                }
            })
            if (data.datas.length == 0) {
                form.find("#newModel").slideDown();
            }
        } else {
            $.alert(data.errorMsg);
        }
    })


}